package com.sip.stream.utils.zfy;

import com.sip.stream.gbstack.GS28181Result;
import com.sip.stream.gbstack.GS28181SDKCallBack;

import io.reactivex.Observable;
import io.reactivex.Single;
import io.reactivex.subjects.BehaviorSubject;

public class GS28181BooleanObservable implements GS28181SDKCallBack {
    private BehaviorSubject<Boolean> resultSubject = BehaviorSubject.create();

    public Single<Boolean> toSingle() {
        return this.resultSubject.firstOrError();
    }

    public Observable<Boolean> toObservable() {
        return this.resultSubject;
    }

    @Override
    public void onComplete(GS28181Result gS28181Result) {
        if (gS28181Result == null) {
            this.resultSubject.onError(new Throwable(""));
        } else if (gS28181Result.isSuccess()) {
            this.resultSubject.onNext(Boolean.TRUE);
        } else {
            this.resultSubject.onError(new Throwable(gS28181Result.message));
        }
    }
}
